package mirfordevoservice.system.req.impl;

import mirfordevoservice.system.GameCenter.DataCenter;
import mirfordevoservice.system.GameCenter.GameDataManager;
import mirfordevoservice.system.req.inter_face.ReqMessage;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.Map;

/**
 * Created by Heart!
 *
 * @Author ZhangChaoJian
 * @Date ${Date}-22:37
 * Wants More Then Try Hard More!
 */

/**
 * 创建新人物请求
 */
public class ReqCreateNewCount implements ReqMessage {

    @Override
    public void receive(ObjectInputStream in, Socket socket) {

    }

    @Override
    public void sendMsg(ObjectOutputStream out) {
    }

    @Override
    public void receiveAndSend(ObjectInputStream in, ObjectOutputStream out, Socket socket) {
       Boolean sendMsg = false;
        try {
            Object msg = in.readObject();
            if (msg instanceof Map) {
                Map<String, String> user_enter_msg = (Map<String, String>) msg;
                sendMsg = GameDataManager.getInstance().createNewUserFormEnterPage(user_enter_msg);
                if (sendMsg) {
                    System.out.println("玩家创建新号成功");
                } else {
                    System.err.println("接受信息有误");
                    System.out.println(msg);
                    return;
                }
            }
            out.writeObject(sendMsg);
            out.flush();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
